package com.pro.framework.api.util;

import java.util.Objects;
import java.util.function.Function;

/**
 * 常用多参数函数式接口工具类
 */
public class Fn {

    /**
     * 三个参数的函数式接口： (A, B, C) -> R
     */
    @FunctionalInterface
    public interface TriFunction<A, B, C, R> {
        R apply(A a, B b, C c);

        default <V> TriFunction<A, B, C, V> andThen(Function<? super R, ? extends V> after) {
            Objects.requireNonNull(after);
            return (a, b, c) -> after.apply(apply(a, b, c));
        }
    }

    /**
     * 四个参数的函数式接口： (A, B, C, D) -> R
     */
    @FunctionalInterface
    public interface QuadFunction<A, B, C, D, R> {
        R apply(A a, B b, C c, D d);

        default <V> QuadFunction<A, B, C, D, V> andThen(Function<? super R, ? extends V> after) {
            Objects.requireNonNull(after);
            return (a, b, c, d) -> after.apply(apply(a, b, c, d));
        }
    }

    /**
     * 五个参数的函数式接口： (A, B, C, D, E) -> R
     */
    @FunctionalInterface
    public interface PentaFunction<A, B, C, D, E, R> {
        R apply(A a, B b, C c, D d, E e);

        default <V> PentaFunction<A, B, C, D, E, V> andThen(Function<? super R, ? extends V> after) {
            Objects.requireNonNull(after);
            return (a, b, c, d, e) -> after.apply(apply(a, b, c, d, e));
        }
    }

    public interface TriConsumer<T, U, V> {
        void accept(T t, U u, V v);
    }

}
